home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: Franz PD / Franz PD Disk #002 (19xx)(Amiga User Group Deutschland e.V.).zip / Franz PD Disk #002 (19xx)(Amiga User Group Deutschland e.V.).adf / Moire / moire.c < prev    next >
C/C++ Source or Header  |  1986-10-22  |  6KB  |  230 lines

  1. /************************************************************************
  2.  * Moire.c -- Yet another graphics dazzler for the Amiga.  This one draws
  3.  *            Moire Patterns in Black and White - they tend to look better
  4.  *            that way.  Uses a borderless backdrop window to make life
  5.  *            easier, and so we get the whole screen if we want it.
  6.  *
  7.  *            Copyright (c) 1985 by Scott Ballantyne
  8.  *            (I.E. Ok to give away for nothing )
  9.  ************************************************************************/
  10.  
  11. #include <exec/types.h> /* Not all of these are used -- I include them */
  12. #include <exec/nodes.h> /* 'cause I'm sick of compiler warnings.       */
  13. #include <exec/lists.h>
  14. #include <exec/exec.h>
  15. #include <exec/execbase.h>
  16. #include <exec/ports.h>
  17. #include <exec/devices.h>
  18. #include <exec/memory.h>
  19. #include <hardware/blit.h>
  20. #include <graphics/copper.h>
  21. #include <graphics/regions.h>
  22. #include <graphics/rastport.h>
  23. #include <graphics/gfxbase.h>
  24. #include <graphics/gfxmacros.h>
  25. #include <graphics/gels.h>
  26. #include <intuition/intuition.h>
  27.  
  28. struct IntuitionBase *IntuitionBase = NULL;
  29. struct GfxBase *GfxBase = NULL;
  30.  
  31.  
  32. #define MAXX   640
  33. #define MAXY   200
  34. struct NewScreen MyScreen =
  35. { 0,0,MAXX,MAXY,1,0,1,HIRES, CUSTOMSCREEN, NULL, "Moire Patterns", 0,0,};
  36.  
  37.    struct NewWindow DrawWindow = {
  38.       0,0,MAXX,MAXY,
  39.       0,1,
  40.       MENUPICK,
  41.       BORDERLESS | BACKDROP | ACTIVATE,
  42.       NULL,
  43.       NULL,
  44.       NULL,
  45.       NULL,
  46.       NULL,
  47.       0,0,0,0,
  48.       CUSTOMSCREEN,
  49.    };
  50.  
  51. struct Screen *Screen = NULL;
  52. struct Window *Backdrop = NULL;
  53. struct RastPort *DrawRP;
  54. struct ViewPort *DrawVP;
  55. struct IntuiMessage  *message;
  56.  
  57. struct MenuItem OnlyMenuItems[4];
  58. struct IntuiText OnlyMenuText[4];
  59. struct Menu OnlyMenu[1];
  60.  
  61. #define SHOW      1
  62. #define ERASE     0
  63.  
  64. main()
  65. {
  66.    ULONG class;
  67.    USHORT code, ItemNum;
  68.  
  69.    if (!(IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",0)))
  70.          exit(1);
  71.  
  72.    if(!(GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",0)))
  73.       cleanitup(2);
  74.  
  75.    if(!(Screen = (struct Screen *)OpenScreen(&MyScreen)))
  76.       cleanitup(3);
  77.  
  78.    DrawWindow.Screen = Screen;
  79.  
  80.    if(!(Backdrop = (struct Window *)OpenWindow(&DrawWindow)))
  81.       cleanitup(4);
  82.  
  83.  
  84.    DrawRP = Backdrop->RPort;     /* Draw into backdrop window */
  85.    DrawVP = &Screen->ViewPort;   /* Set colors in Screens VP  */
  86.    SetBPen(DrawRP, 0);           /* For clean text */
  87.    setcolors();
  88.  
  89.    initmenuitems();
  90.    initmenu();
  91.    SetMenuStrip(Backdrop, &OnlyMenu[0]);
  92.    moire();
  93.  
  94.    FOREVER {
  95.       while(message = (struct IntuiMessage *)GetMsg(Backdrop->UserPort)) {
  96.          class = message->Class;
  97.          code = message->Code;
  98.          ReplyMsg(message);
  99.  
  100.          if (class == MENUPICK && code != MENUNULL) {
  101.             ItemNum = ITEMNUM( code );
  102.             switch (ItemNum) {
  103.                case 0:
  104.                   clearRP();
  105.                   moire();
  106.                   break;
  107.                case 1:
  108.                   ShowTitle(Screen, FALSE);
  109.                   break;
  110.                case 2:
  111.                   ShowTitle(Screen, TRUE);
  112.                   break;
  113.                case 3:
  114.                   ClearMenuStrip(Backdrop);
  115.                   cleanitup(0);
  116.             }
  117.          }
  118.       }
  119.    }
  120. }
  121.  
  122. moire()
  123. {
  124.    register int x, y;
  125.    int endx;
  126.    UBYTE endy;
  127.    double drand48();
  128.  
  129.    OffMenu(Backdrop, NOITEM << 5);
  130.  
  131.    endx = MAXX * drand48();
  132.    endy = MAXY * drand48();
  133.  
  134.    for(x = 0; x <= MAXX; x++) {
  135.       doline(SHOW, x, 0, endx, endy, x, MAXY);
  136.       x++;
  137.       doline(ERASE, x, 0, endx, endy, x, MAXY);
  138.    }
  139.    for(y = 0; y <= MAXY; y++) {
  140.       doline(SHOW, 0, y, endx, endy, MAXX, y);
  141.       y++;
  142.       doline(ERASE, 0, y, endx, endy, MAXX, y);
  143.    }
  144.       OnMenu(Backdrop, NOITEM << 5);
  145. }
  146.  
  147. clearRP()
  148. {
  149.    SetAPen(DrawRP, ERASE);
  150.    SetDrMd(DrawRP, JAM1);
  151.    RectFill(DrawRP, 0, 0, MAXX, MAXY);
  152. }
  153.  
  154. doline(color, x0, y0, x1, y1, x2, y2)
  155. UBYTE color, y0, y1, y2;
  156. int x0, x1, x2;
  157. {
  158.    SetAPen(DrawRP, color);
  159.    SetDrMd(DrawRP, JAM1);
  160.    Move(DrawRP, x0, y0);
  161.    Draw(DrawRP, x1, y1);
  162.    Draw(DrawRP, x2, y2);
  163. }
  164.  
  165. cleanitup(error_code)
  166. int error_code;
  167. {
  168.    if (Backdrop)
  169.       CloseWindow(Backdrop);
  170.    if (Screen)
  171.       CloseScreen(Screen);
  172.    if (GfxBase)
  173.       CloseLibrary(GfxBase);
  174.    if (IntuitionBase)
  175.       CloseLibrary(IntuitionBase);
  176.    exit(error_code);
  177. }
  178.  
  179.  
  180. setcolors()
  181. {
  182.    SetRGB4(DrawVP, 0, 0, 0, 0);
  183.    SetRGB4(DrawVP, 1, 15, 15, 15);
  184. }
  185.  
  186. initmenuitems()
  187. {
  188.    short n;
  189.  
  190.    for(n = 0; n < 4; n++) {  /* One struct for each item */
  191.       OnlyMenuItems[n].NextItem = &OnlyMenuItems[n + 1]; /* next item */
  192.       OnlyMenuItems[n].LeftEdge = 0;
  193.       OnlyMenuItems[n].TopEdge = 10 * n;
  194.       OnlyMenuItems[n].Width = 112;
  195.       OnlyMenuItems[n].Height = 10;
  196.       OnlyMenuItems[n].Flags = ITEMTEXT | ITEMENABLED | HIGHCOMP;
  197.       OnlyMenuItems[n].MutualExclude = 0;
  198.       OnlyMenuItems[n].ItemFill = (APTR)&OnlyMenuText[n];
  199.       OnlyMenuItems[n].SelectFill = NULL;
  200.       OnlyMenuItems[n].Command = 0;
  201.       OnlyMenuItems[n].SubItem = NULL;
  202.       OnlyMenuItems[n].NextSelect = 0;
  203.  
  204.       OnlyMenuText[n].FrontPen = 0;
  205.       OnlyMenuText[n].BackPen = 1;
  206.       OnlyMenuText[n].DrawMode = JAM2;
  207.       OnlyMenuText[n].LeftEdge = 0;
  208.       OnlyMenuText[n].TopEdge = 1;
  209.       OnlyMenuText[n].ITextFont = NULL;
  210.       OnlyMenuText[n].NextText = NULL;
  211.    }
  212.    OnlyMenuItems[3].NextItem = NULL; /* Last item */
  213.  
  214.    OnlyMenuText[0].IText = (UBYTE *)"New Moire";
  215.    OnlyMenuText[1].IText = (UBYTE *)"Hide Title Bar";
  216.    OnlyMenuText[2].IText = (UBYTE *)"Show Title Bar";
  217.    OnlyMenuText[3].IText = (UBYTE *)"QUIT!";
  218. }
  219. initmenu()
  220. {
  221.    OnlyMenu[0].NextMenu = NULL;                 /* No more menus */
  222.    OnlyMenu[0].LeftEdge = 0;
  223.    OnlyMenu[0].TopEdge = 0;
  224.    OnlyMenu[0].Width = 85;
  225.    OnlyMenu[0].Height = 10;
  226.    OnlyMenu[0].Flags = MENUENABLED;             /* All items selectable */
  227.    OnlyMenu[0].MenuName = "Actions";
  228.    OnlyMenu[0].FirstItem = &OnlyMenuItems[0];   /* Pointer to first item */
  229. }
  230.